const setCookie = function(name, value, expires) {
  var str = name + '=' + escape(value) + ';httpOnly=false'
  if (expires) { str += ';expires=' + expires.toGMTString() }

  document.cookie = str
}

const getCookie = function(name) {
  var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  var arr = document.cookie.match(reg)
  if (arr) { return unescape(arr[2]) } else { return null }
}

const delCookie = function(name) {
  var exp = new Date()
  exp.setTime(exp.getTime() - 1)
  var cval = getCookie(name)
  if (cval != null) { document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString() }
}

export default{
  set: setCookie,
  get: getCookie,
  del: delCookie
}
